function HAZ_autopars

k0=8;
L=[];
hh=[];
mf=findobj('Tag','HAZ_MAIN');udata=get(mf,'UserData');X=udata.X;n=length(X);
for k=2:2:k0;
  nu=0;mu=0;
  K=K_def('opt',nu,k,mu);
  beta=K.beta;var=K.var;
  TK=(abs(beta)^(2*nu+1)*var^(k-nu))^(2/(2*k+1));
  gamma=(var/beta^2)^(1/(2*k+1));
  h_m=h_ms(X,K);
  [hn,pociter,iterace]=iter_bisnewt(h_m,X,K,50,0.0001);
  hh=[hh,hn];
  Lp=TK*(2*(k+nu)+1)*gamma/(2*n*k*hn^(2*nu+1));
  L=[L,Lp];
end

[Lmin,Imin]=min(L);
h=hh(Imin);
hs=num2str(h);
k=2*Imin;
ks=num2str(k);
K=K_def('opt',nu,k,mu);
xx=udata.xx;f_est=K_dest(xx,X,h,K);udata.h=h;udata.f_est=f_est;udata.K=K;set(mf,'UserData',udata);

autoparfig=figure( ...
   'Visible','on', ...
   'Name','Estimation Parameters', ...
   'Units','Normalized',...
   'Tag','HAZ_AUTOPAR',...
   'NumberTitle','off');

uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.3,.85,.4,.1], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.5,...
        'String','Automatically set parameters');

% list of parameters
uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.7,.6,.08], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String',['Optimal kernel of order:']);
uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.6,.6,.08], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String',['Bandwidth:']);
% parameters
uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.5,.7,.6,.08], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String',[ks]);
uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.5,.6,.6,.08], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String',[hs]);

% Close button
uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.8,0.1,.15,0.05], ...
        'String','Close', ...
        'Callback','delete(gcf)');
end % function

